package com.mdlib.helper.ui.fragments.rush.me;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.ljlib.core.base.BaseFragment;
import com.ljlib.help.R;
import com.mdlib.helper.api.DataManager;
import com.mdlib.helper.api.network.RxHelper;
import com.mdlib.helper.api.network.RxSubscribe;
import com.mdlib.helper.event.ShareEvent;
import com.mdlib.helper.model.entity.ShareEntity;
import com.mdlib.helper.ui.UIHelper;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 作者：HQY on 16/11/30 14:29
 * 邮箱：hqy_xz@126.com
 */

public class RushShareFragment extends BaseFragment {


    @Bind(R.id.tv_rush_share_rules_one)
    TextView mTvRushShareRulesOne;
    @Bind(R.id.tv_rush_share_rules_two)
    TextView mTvRushShareRulesTwo;
    @Bind(R.id.tv_rush_share_submit)
    TextView mTvRushShareSubmit;
    private ShareEntity share;

    public static RushShareFragment newInstance() {
        return new RushShareFragment();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_rush_share;
    }

    @Override
    protected void initView(View rootView) {
        super.initView(rootView);
        getRushShareInfo();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(ShareEvent shareEvent) {
        if (shareEvent.getType() == 0) {
        }

    }
    private void getRushShareInfo() {
        addSubscribe(DataManager.getInstance().getUserApi()
                .getRushShareInfo()
                .compose(RxHelper.<ShareEntity>defaultHandleResult())
                .subscribe(new RxSubscribe<ShareEntity>() {
                    @Override
                    protected void onSucc(ShareEntity shareEntity) {
                        share = shareEntity;
                        mTvRushShareRulesOne.setText(getActivity().getResources().getString(R.string.rush_share_rules_one, share.getReg_money()));
                        mTvRushShareRulesTwo.setText(getActivity().getResources().getString(R.string.rush_share_rules_two, share.getFirst_send_money()));
                    }

                    @Override
                    protected void onFail(String msg) {

                    }
                }));
    }


    @OnClick(R.id.tv_rush_share_submit)
    public void onClick() {

        UIHelper.showDialogShare(getActivity(), share);
    }
}
